package com.example.day13;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Message;

import android.os.Handler;
import android.util.Log;

import java.util.HashMap;

public class WorkThread extends Thread {
    public static final int MAP=1;
    public static final int STIRING=2;
    public static final int FILE=3;
    Handler handler;
    Message message;
    String url;
    int choose;
    HashMap<String, String> paramsMap;

    public WorkThread(int choose,Handler handler,Message message,String url, HashMap<String, String> paramsMap ){
        this.handler=handler;
        this.message=message;
        this.url=url;
        this.paramsMap=paramsMap;
        this.choose=choose;
    }

    @Override
    public void run() {
        super.run();
        byte[] b=new HttpTools().requestPost(null,url);

        switch(choose){
            case MAP:
                Bitmap map= null;
                if(b==null||b.length==0){
                    map=null;
                }else{
                    map= BitmapFactory.decodeByteArray(b,0,b.length);
                }
                message.obj=map;
            break;
            case STIRING:
                if(b==null||b.length==0){
                    message.obj=null;
                }else{
                    String a= new String(b);
                    Log.e("###",a);
                    message.obj=a;
                }
                break;
            case FILE:
                break;
        }
        handler.sendMessage(message);
    }

}
